//
// Created by Administrator on 2021/5/31.
//
#include <iostream>
using namespace std;

// 判断3的幂
class Solution {
public:
    bool isPowerOfThree(int n) {
        if (n < 1) return false;
        while (n % 3 == 0) {
            n /= 3;
        }
        return n == 1;
    }
};

int main() {
    Solution sol;
    cout << sol.isPowerOfThree(3) << endl;
    cout << sol.isPowerOfThree(4) << endl;
    cout << sol.isPowerOfThree(9) << endl;
    cout << sol.isPowerOfThree(1) << endl;
    cout << sol.isPowerOfThree(27) << endl;
    return 0;
}